package org.yray.neo4j.hanlp;

import cn.hutool.crypto.digest.MD5;
import lombok.Data;
import java.util.HashMap;
import java.util.Map;

@Data
public class QuestionEntity {
    private static Map<String,QuestionEntity> questionEntityMap=new HashMap<>();
    private static Map<String,String> answerMap=new HashMap<>();
    private String id;
    private String question;
    private String answerLen;

    public QuestionEntity(String id, String question)
    {
        this.id=id;
        this.question=question;
    }

    public String getAnswer()
    {
        return answerMap.get(this.id);
    }

    public static String getAnswerById(String answerId)
    {
       return answerMap.get(answerId);
    }

    public static QuestionEntity getQuestionById(String id)
    {
        return questionEntityMap.get(id);
    }


    public static QuestionEntity ifAbsentQuestion(String question)
    {
        String questionId=MD5.create().digestHex16(question);
        QuestionEntity questionEntity= questionEntityMap.computeIfAbsent(questionId,v->new QuestionEntity(questionId,question));
        return questionEntity;
    }

    public static void ifAbsentAnswer(String id,String answer)
    {
        answerMap.computeIfAbsent(id,v->answer);
    }


    @Override
    public String toString()
    {
        StringBuilder sb=new StringBuilder();
        sb.append("question=").append(question).append("answer=").append(getAnswerById(id));
        return  sb.toString();
    }
}
